import { createRouter, createWebHashHistory } from 'vue-router'
import Login from '../views/Login.vue'
import My from '../views/My.vue'
import Cart from '../views/Cart.vue'
import Xq from '@/views/Xq.vue'

const routes = [
  {
    path:'/',
    redirect: '/login',  // 重定向:重新指向其它path,会改变网址
  },
  {
    path: '/login',
    component: Login
  },
  {
    path:'/my',
    component: My
  },
  {
    path:'/cart',
    component: Cart
  },
  {
    path:'/xq',
    component: Xq
  },
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

// router.beforeEach(async (to, from) => {
//    if (
//      // 检查用户是否已登录
//      !isAuthenticated &&
//      // ❗️ 避免无限重定向
//      to.name !== 'Login'
//    ) {
//      // 将用户重定向到登录页面
//      return { name: 'Login' }
//    }
//  })
export default router
